﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mailer.Model.Types;
using NHibernate;
using System.Net.Mail;
using NHibernate.Criterion;

namespace Mailer.Model.Repositories
{
	public class ListRepository
	{
		
		
		
		public static List<List> GetForApplications(Guid appid)
		{
			List<List> ret = new List<List>();


			ISession sess = SessionUtilities.BeginSession();
			if (sess != null)
			{
				Application app = sess.Get<Application>(appid);
				if (app != null)
				{
					foreach (List l in app.Lists)
						ret.Add(l);
				}
				SessionUtilities.EndSession(sess);
			}
			return ret;

		}




		public static bool AddRecipient(ISession sess, ITransaction transaction, Guid listid, MailAddress email)
		{
			return false;
		}

		public static bool AddRecipient(ISession sess, ITransaction transaction, Guid listid, string email)
		{
			return false;
		}

		public static bool AddRecipient(ISession sess, ITransaction transaction, Guid listid, string email, string displayname)
		{
			return false;
		}



		public static bool RemoveRecipient(ISession sess, ITransaction transaction, Guid listid, MailAddress email)
		{
			return false;
		}

		public static bool RemoveRecipient(ISession sess, ITransaction transaction, Guid listid, string email)
		{
			return false;
		}


		public static List GetByPublicID(Application app, string tag)
		{
			List ret = null;


			ISession sess = SessionUtilities.BeginSession();
			if (sess != null)
			{
				ret = sess.CreateCriteria<List>()
					.Add(Expression.Eq("ApplicationID", app.ID))
					.Add(Expression.Eq("ShortName", tag))
					.UniqueResult<List>();

				SessionUtilities.EndSession(sess);
			}

			return ret;
		}


	}
}
